﻿using System;
using UnityEngine;

public class EnemyAnimatorTrigger: MonoBehaviour
{

    private  EnemyStateController mEnemyStateController;
    
    private void Awake()
    {
        mEnemyStateController = GetComponentInParent<EnemyStateController>();
    }

    public void TriggerFinish()
    {
        mEnemyStateController.stateMachine.TriggerFinish();
    }

    public void TriggerAttack()
    {
        Collider2D collider2D = Physics2D.OverlapCircle(mEnemyStateController.GetAttackCheckPos(),
            mEnemyStateController.GetEnemyStateInfo().AttackRadius,Setting.PlayerLayer);
        if (collider2D)
        {
            PlayerStateController playerStateController = collider2D.GetComponent<PlayerStateController>();
            if (playerStateController != null)
            {
                playerStateController.Damage(new DamgeInfo()
                {
                    attacker = mEnemyStateController.characterBase,
                    targeter = playerStateController.characterBase,
                    damage = mEnemyStateController.GetDamage(),
                });
            }
            
        }
    }

    public void TriggerCounterWindowOpen()
    {
        mEnemyStateController.OpenCounterWindow();
    }
    
    public void TriggerCounterWindowClose()
    {
        mEnemyStateController.CloseCounterWindow();
    }
    
}